<div class="smart-pop" >
    <div id="add_form" class="layui-form" style="display: none;">
        <input type="text" name="roleId" value="<%=roleId%>" >
        <input type="text" name="resIds">
    </div>

    <ul id="authorization" class="ztree"></ul>
</div>
<script>
    layui.use(['layer', 'table', 'form'], function () {
        var layer = layui.layer;
        var $ = layui.$;
        var setting = {
            data: {
                key: {
                    title: "t"
                },
                simpleData: {
                    enable: true
                }
            },
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "ps", "N": "ps" }
            },
            view: {
                showIcon: true,
                showTitle: false
            },
            callback: {
                onCheck: zTreeOnCheck
            }
        };


        //获取左侧ztree
        getZtree();

        function zTreeOnCheck(event, treeId, treeNode) {
            var treeObj = $.fn.zTree.getZTreeObj("authorization");
            var nodes = treeObj.getCheckedNodes(true);
            var resIds = "";
            for (var i = 0; i < nodes.length; i++) {
                var id = nodes[i].id;
                resIds += id + ",";
            }

            $(".smart-pop input[name=resIds]").val(resIds);
        }

        function getZtree() {
            var roleId = $("input[name='roleId']").val();
            $.ajax({
                url: 'sys/role/getResList',
                data: {"roleId":roleId},
                success: function (result) {
                    if (result.success) {
                        var zNodes = result.data;
                        var treeObj = $.fn.zTree.init($("#authorization"), setting, zNodes);
                        treeObj.expandAll(true);
                    }
                },
            });
        }

    });
</script>
